<template>
  <div class="shop-info" v-if="isShowComp">
    <!-- 顶部 -->
    <div class="shop-top">
      <img v-lazy="shops.logo" alt />
      <span class="top-title">{{ shops.name }}</span>
    </div>

    <!-- 中间 -->
    <div class="shop-middle">
      <!-- 左块 -->
      <div class="middle-item middle-left">
        <!-- 总销量 -->
        <div class="middle-item-info">
          <div class="info-number">{{ shops.sells | sellCountFilter }}</div>
          <div class="info-text">总销量</div>
        </div>
        <!-- 全部宝贝 -->
        <div class="middle-item-info">
          <div class="info-number">{{ shops.goodsCount }}</div>
          <div class="info-text">全部宝贝</div>
        </div>
      </div>
      <!-- 右块 -->
      <div class="middle-item middle-right">
        <table>
          <tr v-for="(item, index) in shops.score" :key="'score' + index">
            <td>{{ item.name }}</td>
            <td :class="item.isBetter ? 'red' : 'green'">{{ item.score }}</td>
            <td :class="{'better-more': item.isBetter}" class="better">
              <span>{{ item.isBetter ? '高' : '低' }}</span>
            </td>
          </tr>
        </table>
      </div>
    </div>

    <!-- 底部 -->
    <div class="shop-bottom">
      <div class="enter-shop">进店逛逛</div>
    </div>
  </div>
</template>

<script>
export default {
  name: "DetailShopInfo",

  // 过滤器
  filters: {
    sellCountFilter: function (value) {
      if (value > 10000) return (value / 10000).toFixed(1) + "万";
      return value;
    },
  },

  // 父组件传递数据
  props: {
    shops: {
      type: Object,
      default() {
        return {};
      },
    },
  },

  // 计算属性
  computed: {
    isShowComp() {
      return Object.keys(this.shops).length != 0;
    },
  },
};
</script>

<style lang="less" scoped>
.shop-info {
  padding: 25px 8px;
  border-bottom: 5px solid #f2f5f8;
  .shop-top {
    // 顶部logo+文字描述样式
    img {
      margin-right: 15px;
      width: 45px;
      height: 45px;
      border-radius: 50%;
      vertical-align: middle;
      border: 1px solid rgba(0, 0, 0, 0.1);
    }
  }
  .shop-middle {
    // 中间
    display: flex;
    align-items: center;
    text-align: center;
    .middle-item {
      flex: 1;
    }
    .middle-left {
      // 左边块
      display: flex;
      // flex均等分排布
      justify-content: space-evenly;
      border-right: 1px solid rgba(0, 0, 0, 0.1);
      color: #333333;
      .middle-item-info {
        .info-number {
          font-size: 18px;
        }
        .info-text {
          margin-top: 10px;
          font-size: 12px;
        }
      }
      // .info-goods {
      //   flex: 50%;
      // }
    }
    .middle-right {
      // 右边块
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      color: #333333;
      font-size: 13px;
      table > tr > td {
        text-align: left;
        padding: 5px 8px;
      }
      .better span {
        padding: 1px;
        text-align: center;
        color: var(--color-background);
        background-color: #5ea732;
      }
      .better-more span {
        background-color: #f13e3a;
      }
    }
    .green {
      color: #5ea732;
    }
    .red {
      color: #f13e3a;
    }
  }
  .shop-bottom {
    // 底部
    margin-top: 15px;
    text-align: center;
    .enter-shop {
      display: inline-block;
      font-size: 14px;
      background-color: #f2f5f8;
      width: 150px;
      height: 30px;
      text-align: center;
      line-height: 30px;
      border-radius: 10px;
    }
  }
}
</style>